import { QXEvent } from "qx-util";
import { IParam, GridActionType, IGridAbility, IGridControllerParams, IGridStore, GridController, ICtrlEvent, IGridController, IGridModel, ControlVOBase } from "@/core";
import { useGridAction, useGridBasic, useGridControllerParams, useGridProps } from "@/hooks/widget/use-grid";
import { GridControlVO } from './main-grid-vo';
import { model } from "./main-grid-model";
import GridService from "@/core/modules/ctrl-service/grid-service";
// 基于template/src/widgets/{{appEntities}}/{{ctrls@GRID}}-grid/{{spinalCase ctrl.codeName}}-grid-hook.ts.hbs生成
/**
 * 获取输入参数
 *
 * @export
 * @return {*}
 */
export function useProps() {
	return {
		...useGridProps(),
	};
}

/**
 * 获取基础数据
 *
 * @export
 * @param {*} props
 * @return {*}
 */
export function useBasic(props: any) {
	return {
		...useGridBasic(model, props),
	};
}

/**
 * 获取行为
 *
 * @export
 */
export function useAction(controller: any) {
	return {
		...useGridAction(controller),
	};
}

/**
 * 获取控制器
 *
 * @export
 * @param {IParam} props
 * @param {QXEvent<ICtrlEvent<GridActionType, IGridAbility>>} evt
 * @return {*}
 */
export function useController(
	props: IParam,
	evt: QXEvent<ICtrlEvent<GridActionType, IGridAbility>>,
    otherParams: IParam = {},
): IGridController<IGridStore, IGridAbility> {
	const params: IGridControllerParams<GridActionType, IGridAbility> =
		useGridControllerParams<IGridStore, IGridModel>(model, props, evt, otherParams);
    const ctrlService = new GridService<ControlVOBase[]>(GridControlVO, model.entityCodeName);
  	Object.assign(params, { ctrlService });
  	return new GridController(params);
}